package com.andaily.domain.dto.user;

import com.andaily.domain.shared.GuidGenerator;
import com.andaily.domain.shared.PasswordHandler;
import com.andaily.domain.user.User;
import org.apache.commons.lang.StringUtils;

/**
 * @author Shengzhao Li
 */
public class RegisterUserDTO {

    private String guid;
    private String email;
    private String password;
    private String rePassword;
    private String city;
    private String nickName;
    private String cellPhone;

    public RegisterUserDTO() {
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRePassword() {
        return rePassword;
    }

    public void setRePassword(String rePassword) {
        this.rePassword = rePassword;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public User toRegisterUser() {
        String encryptPass = PasswordHandler.encryptPassword(this.password);
        User user = new User(this.email, encryptPass, this.city).verifyCode(GuidGenerator.generate());
        String phone = (StringUtils.isEmpty(this.cellPhone) ? null : this.cellPhone);
        user.update(this.nickName, phone);
        //register, archived is true
        user.archived(true);
        return user;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getCellPhone() {
        return cellPhone;
    }

    public void setCellPhone(String cellPhone) {
        this.cellPhone = cellPhone;
    }
}
